<?
class db{	private $link_id;
	private $query_id;

	function __construct ($hostname="",$user="",$password="",$db=""){     $this->link_id= mysql_connect($hostname,$user,$password);
     if(!$this->link_id && $db!="") {   	  $this->show_error("Error connect Mysql or wrong table name.");
   	  }else{   	   if(!mysql_select_db($db, $this->link_id)) echo"error";
   	  }
	}

	function __destruct(){	 $this->close();
	}

	function query($string="",$arg=false){     if($arg){
      $tmp=explode(";",$string); 	   foreach($tmp as $key=>$value){
        if(!empty($value))$this->query_id=mysql_query($value,$this->link_id);
       };
      }else{	  $this->query_id=mysql_query($string,$this->link_id);      }
     $this->show_error($string);
     return $this->query_id;
    }

	function result_array($query_id=""){
     if ( $query_id != "" )$this->query_id=$query_id;
     $res=array();
     for($i=0;$i<$this->total_rows($this->query_id);$i++){
      array_push($res ,mysql_fetch_assoc($this->query_id));
     }
     return $res;
    }

	function result_object($query_id=""){
     if($query_id != "" )$this->query_id=$query_id;
     $res=array(0);
     for($i=0;$i<$this->total_rows($this->query_id);$i++){
      array_push($res ,mysql_fetch_object($this->query_id));
     }
     return $res;
    }

	function show_error($query){      if(mysql_error($this->link_id)){      echo $query."<br />";      echo mysql_error($this->link_id);
      }
    }

	function  total_rows($query_id=""){
     if($query_id != "" )$this->query_id=$query_id;     $total_rows=mysql_num_rows($this->query_id);
     return $total_rows;
	}

	function close(){	return mysql_close($this->link_id);
	}

	function retur_ins_id(){ 	return mysql_insert_id($this->link_id);
	}

	function take_info($return,$table,$compared_sql,$compared_request){    $tmp=$this->result_array($this->query("SELECT $return From $table WHERE $compared_sql='$compared_request' LIMIT 1;"));
	 return $tmp [0] [$return];
	}

}?>